/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.dworks.apps.asecure.blacklist;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import android.app.SearchManager;
import android.app.WallpaperManager;
import android.content.ComponentName;
import android.content.ContentProvider;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.SQLException;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.DropBoxManager;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.speech.tts.TextToSpeech;
import android.text.TextUtils;
import android.util.AndroidException;
import android.util.Log;
import android.view.Display;
/**
* The Settings provider contains global system-level device preferences.
*/
public final class Settings {
/**
* @hide - Private call() method on SettingsProvider to read from 'system' table.
*/
public static final String CALL_METHOD_GET_SYSTEM = "GET_system";
/**
* @hide - Private call() method on SettingsProvider to read from 'secure' table.
*/
public static final String CALL_METHOD_GET_SECURE = "GET_secure";
/**
* @hide - Private call() method on SettingsProvider to read from 'global' table.
*/
public static final String CALL_METHOD_GET_GLOBAL = "GET_global";
/**
* @hide - User handle argument extra to the fast-path call()-based requests
*/
public static final String CALL_METHOD_USER_KEY = "_user";
/** @hide - Private call() method to write to 'system' table */
public static final String CALL_METHOD_PUT_SYSTEM = "PUT_system";
/** @hide - Private call() method to write to 'secure' table */
public static final String CALL_METHOD_PUT_SECURE = "PUT_secure";
/** @hide - Private call() method to write to 'global' table */
public static final String CALL_METHOD_PUT_GLOBAL= "PUT_global";
/**
* Activity Extra: Limit available options in launched activity based on the given authority.
* <p>
* This can be passed as an extra field in an Activity Intent with one or more syncable content
* provider's authorities as a String[]. This field is used by some intents to alter the
* behavior of the called activity.
* <p>
* Example: The {@link #ACTION_ADD_ACCOUNT} intent restricts the account types available based
* on the authority given.
*/
public static final String EXTRA_AUTHORITIES = "authorities";
/**
* Activity Extra: Limit available options in launched activity based on the given account
* types.
* <p>
* This can be passed as an extra field in an Activity Intent with one or more account types
* as a String[]. This field is used by some intents to alter the behavior of the called
* activity.
* <p>
* Example: The {@link #ACTION_ADD_ACCOUNT} intent restricts the account types to the specified
* list.
*/
public static final String EXTRA_ACCOUNT_TYPES = "account_types";
public static final String EXTRA_INPUT_METHOD_ID = "input_method_id";
private static final String JID_RESOURCE_PREFIX = "android";
public static final String AUTHORITY = "settings";
private static final String TAG = "Settings";
private static final boolean LOCAL_LOGV = false;
// Lock ensures that when enabling/disabling the master location switch, we don't end up
// with a partial enable/disable state in multi-threaded situations.
private static final Object mLocationSettingsLock = new Object();
public static class SettingNotFoundException extends AndroidException {
public SettingNotFoundException(String msg) {
super(msg);
}
}
/**
* Common base for tables of name/value settings.
*/
public static class NameValueTable implements BaseColumns {
public static final String NAME = "name";
public static final String VALUE = "value";
protected static boolean putString(ContentResolver resolver, Uri uri,
String name, String value) {
// The database will take care of replacing duplicates.
try {
ContentValues values = new ContentValues();
values.put(NAME, name);
values.put(VALUE, value);
resolver.insert(uri, values);
return true;
} catch (SQLException e) {
Log.w(TAG, "Can't set key " + name + " in " + uri, e);
return false;
}
}
public static Uri getUriFor(Uri uri, String name) {
return Uri.withAppendedPath(uri, name);
}
}
// Thread-safe.
private static class NameValueCache {
private final String mVersionSystemProperty;
private final Uri mUri;
private static final String[] SELECT_VALUE =
new String[] { Settings.NameValueTable.VALUE };
private static final String NAME_EQ_PLACEHOLDER = "name=?";
// Must synchronize on 'this' to access mValues and mValuesVersion.
private final HashMap<String, String> mValues = new HashMap<String, String>();
private long mValuesVersion = 0;
private ContentProviderClient mContentProvider = null;
// The method we'll call (or null, to not use) on the provider
// for the fast path of retrieving settings.
private final String mCallGetCommand;
private final String mCallSetCommand;
public NameValueCache(String versionSystemProperty, Uri uri,
String getCommand, String setCommand) {
mVersionSystemProperty = versionSystemProperty;
mUri = uri;
mCallGetCommand = getCommand;
mCallSetCommand = setCommand;
}
private ContentProviderClient lazyGetProvider(ContentResolver cr) {
ContentProviderClient cp = null;
synchronized (this) {
cp = mContentProvider;
if (cp == null) {
cp = mContentProvider = cr.acquireContentProviderClient(mUri.getAuthority());
}
}
return cp;
}
}
/**
* System settings, containing miscellaneous system preferences. This
* table holds simple name/value pairs. There are convenience
* functions for accessing individual settings entries.
*/
public static final class System extends NameValueTable {
public static final String SYS_PROP_SETTING_VERSION = "sys.settings_system_version";
/**
* The content:// style URL for this table
*/
public static final Uri CONTENT_URI =
Uri.parse("content://" + AUTHORITY + "/system");
private static final NameValueCache sNameValueCache = new NameValueCache(
SYS_PROP_SETTING_VERSION,
CONTENT_URI,
CALL_METHOD_GET_SYSTEM,
CALL_METHOD_PUT_SYSTEM);
public static int getInt(Context context, String name, int def) {
return PreferenceManager.getDefaultSharedPreferences(context).getInt(name, def);
}
/**
* Convenience function for updating a single settings value as an
* integer. This will either create a new entry in the table if the
* given name does not exist, or modify the value of the existing row
* with that name. Note that internally setting values are always
* stored as strings, so this function converts the given value to a
* string before storing it.
*
* @param cr The ContentResolver to access.
* @param name The name of the setting to modify.
* @param value The new value for the setting.
* @return true if the value was set, false on database errors
*/
public static boolean putInt(ContentResolver cr, String name, int value) {
return false;//putIntForUser(cr, name, value, UserHandle.myUserId());
}
/**
* Whether the blacklisting feature for phone calls is enabled
* @hide
*/
public static final String PHONE_BLACKLIST_ENABLED = "phone_blacklist_enabled";
/**
* Whether a notification should be shown when a call/message is blocked
* @hide
*/
public static final String PHONE_BLACKLIST_NOTIFY_ENABLED = "phone_blacklist_notify_enabled";
/**
* Whether the blacklisting feature for phone calls from private numbers is enabled
* @hide
*/
public static final String PHONE_BLACKLIST_PRIVATE_NUMBER_MODE = "phone_blacklist_private_number_enabled";
/**
* Whether the blacklisting feature for phone calls from unknown numbers is enabled
* @hide
*/
public static final String PHONE_BLACKLIST_UNKNOWN_NUMBER_MODE = "phone_blacklist_unknown_number_enabled";
/**
* Constants to be used for {@link PHONE_BLACKLIST_PRIVATE_NUMBER_MODE} and
* {@link PHONE_BLACKLIST_UNKNOWN_NUMBER_MODE}.
* @hide
*/
public static final int BLACKLIST_DO_NOT_BLOCK = 0;
/**
* @hide
*/
public static final int BLACKLIST_BLOCK = 1;
/**
* @hide
*/
public static final int BLACKLIST_PHONE_SHIFT = 0;
/**
* @hide
*/
public static final int BLACKLIST_MESSAGE_SHIFT = 4;
/**
* Whether the regex blacklisting feature for phone calls is enabled
* @hide
*/
public static final String PHONE_BLACKLIST_REGEX_ENABLED = "phone_blacklist_regex_enabled";
}
}